//--------------------------------------------
//
// copyright@2008,all right reserved by ax.
//
//
//     PROJECT   :   futrue
//
//     FILE      :   BaseMsg.h
//
//     PURPOSE   :   futrue project main file
//   
//     DATE      :   2008/10/01
//
//     AUTHOR    :   ax
//
//--------------------------------------------
#ifndef __FUTRUE_BASE_MSG_H__
#define __FUTRUE_BASE_MSG_H__
#define MAX_MSG_SIZE (1400)
class BaseMsg
{
public:
	BaseMsg(int nMaxSize = MAX_MSG_SIZE):m_nMaxSize(nMaxSize)
	{
		m_nSize = 0;
		m_dwIp = 0;
		m_wPort = 0;
		m_szMsg = new char [ m_nMaxSize];
	}
	~BaseMsg()
	{
		if(m_szMsg)
			delete[] m_szMsg;
	}

	const char* GetMsgBuffer()const { return m_szMsg;}
	int   GetMsgSize () const { return m_nSize;}

	void  GetAddr(unsigned int& dwIp,unsigned short& wPort)
	{
		dwIp = m_dwIp;
		wPort = m_wPort;
	}
	void SetAddr(unsigned int dwIp,unsigned short wPort)
	{
		m_dwIp  = dwIp;
		m_wPort = wPort;
	}

	int  GetMaxSize()const { return m_nMaxSize;}
	void FillMsgBuffer(const char* pData,int nSize)
	{
		if(pData && m_szMsg && m_nMaxSize > nSize)
		{
			m_nSize = nSize;
			memcpy(m_szMsg,pData,nSize);
		}
	}
private:	
	char *m_szMsg;
	int  m_nSize;

	unsigned int    m_dwIp;
	unsigned short  m_wPort;
	const int		m_nMaxSize;
 };
#endif